#!/bin/bash
set -e
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "$script_dir/functions"

for builder in $tb_builders
do
  for file in sha256sums-unsigned-build.txt.asc sha256sums-unsigned-build.incrementals.txt.asc
  do
    tmpfile=$(mktemp)
    chmod 644 "$tmpfile"
    for url in \
      "https://people.torproject.org/~$builder/builds/$SIGNING_PROJECTNAME/$tbb_version-build$tbb_version_build/$file" \
      "https://tb-build-04.torproject.org/~$builder/builds/$SIGNING_PROJECTNAME/$tbb_version_type/unsigned/$tbb_version-build$tbb_version_build/$file" \
      "https://tb-build-05.torproject.org/~$builder/builds/$SIGNING_PROJECTNAME/$tbb_version_type/unsigned/$tbb_version-build$tbb_version_build/$file"
    do
      if wget -q -O "$tmpfile" "$url"; then
        mv "$tmpfile" "$signed_version_dir/$file-$builder"
        echo "Added $file-$builder"
        break
      fi
    done
  done
done
exit 0
